//
//  UITableViewCell+TKIM.m
//  TKIM
//
//  Created by liupm on 15/10/29.
//  Copyright © 2015年 liupm. All rights reserved.
//

#import "TKIMUITableViewCell.h"

@implementation TKIMUITableViewCell

- (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setBackgroundColor:[UIColor whiteColor]];
        _topLineStyle = CellLineStyleNone;
        _bottomLineStyle = CellLineStyleDefault;
        
        [self.contentView addSubview:self.headView];
        [self.contentView addSubview:self.title];

    }
    return self;
}



-(UIImageView *)headView
{
    if (!_headView)
    {
        _headView =  [[UIImageView alloc] initWithFrame:CGRectMake(10,0, 45, 45)];
        _headView.clipsToBounds = YES;
        _headView.layer.cornerRadius = 45/2.0;
    }
    return _headView;
}


-(UILabel *)title
{
    if (!_title)
    {
        _title = [[UILabel alloc] initWithFrame:CGRectMake(self.headView.frame.size.width+self.headView.frame.origin.x+10, 0, TKIMScreenWidth-140, 55)];
        _title.font = [UIFont systemFontOfSize:16.0f];
        _title.textColor = [UIColor grayColor];
    }
    return _title;
}




- (void) layoutSubviews
{
    [super layoutSubviews];
    [self.topLine setTop:0];
    [self.bottomLine setTop:self.height - _bottomLine.height];
    [self setBottomLineStyle:_bottomLineStyle];
    [self setTopLineStyle:_topLineStyle];
    
    self.headView.top = (self.height-45)/2;
    self.title.height = self.height;
}

- (void) setTopLineStyle:(CellLineStyle)style
{
    _topLineStyle = style;
    if (style == CellLineStyleDefault) {
        [self.topLine setLeft:_leftFreeSpace];
        [self.topLine setWidth:self.width - _leftFreeSpace];
        [self.topLine setHidden:NO];
    }
    else if (style == CellLineStyleFill) {
        [self.topLine setLeft:0];
        [self.topLine setWidth:self.width];
        [self.topLine setHidden:NO];
    }
    else if (style == CellLineStyleNone) {
        [self.topLine setHidden:YES];
    }
}

- (void) setBottomLineStyle:(CellLineStyle)style
{
    _bottomLineStyle = style;
    if (style == CellLineStyleDefault) {
        [self.bottomLine setLeft:_leftFreeSpace];
        [self.bottomLine setWidth:self.width - _leftFreeSpace];
        [self.bottomLine setHidden:NO];
    }
    else if (style == CellLineStyleFill) {
        [self.bottomLine setLeft:0];
        [self.bottomLine setWidth:self.width];
        [self.bottomLine setHidden:NO];
    }
    else if (style == CellLineStyleNone) {
        [self.bottomLine setHidden:YES];
    }
}

- (UIView *) bottomLine
{
    if (_bottomLine == nil) {
        _bottomLine = [[UIView alloc] init];
        [_bottomLine setHeight:0.5f];
        [_bottomLine setBackgroundColor:[TKIMColorHelper stringToColor:@"#B7B7B7"]];
        [_bottomLine setAlpha:0.4];
        [self.contentView addSubview:_bottomLine];
    }
    return _bottomLine;
}

- (UIView *) topLine
{
    if (_topLine == nil) {
        _topLine = [[UIView alloc] init];
        [_topLine setHeight:0.5f];
        [_topLine setBackgroundColor:[UIColor lightGrayColor]];
        [_topLine setAlpha:0.4];
        [self.contentView addSubview:_topLine];
    }
    return _topLine;
}


@end
